<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台管理系统 - Layui</title>
    {load href="/static/admin/layui/js/jquery-3.3.1.min.js" /}
    {load href="/static/admin/layui/layui.js" /}
    {load href="/static/admin/layui/css/layui.css" /}
    {load href="/static/js/md5/md5.js" /}
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">后台管理系统</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a id="updateAll" href="javascript:updateStatua()">更新贷款状态</a></li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    <span id="username" class="username"></span>
                </a>
                <!--<dl class="layui-nav-child">-->
                    <!--<dd><a href="">基本资料</a></dd>-->
                    <!--<dd><a href="">安全设置</a></dd>-->
                <!--</dl>-->
            </li>
            <li class="layui-nav-item"><a href="javascript:showTime()">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-shrink=""  lay-filter="test">

                <li class="layui-nav-item {if ($Request.path == 'login/Sign/addSign') OR ($Request.path == 'login/Sign/allSign') }layui-nav-itemed{/if}">
                    <a class="" href="javascript:;">渠道管理</a>
                    <dl class="layui-nav-child">
                        <dd class="{if $Request.path == 'login/Sign/addSign'}layui-this{/if}"><a href="/login/Sign/addSign">添加渠道</a></dd>
                        <dd class="{if $Request.path == 'login/Sign/allSign'}layui-this{/if}"><a href="/login/Sign/allSign">管理渠道</a></dd>
                        <!--<dd><a href="/admin/Category/index">推广等级</a></dd>-->
                        <!--<dd><a href="/admin/Grade/fetch_add_grade">添加等级</a></dd>-->
                    </dl>
                </li>

                <li class="layui-nav-item {if ($Request.path == 'login/Show/index') OR ($Request.path == 'login/Registered/index') }layui-nav-itemed{/if}">
                    <a class="" href="javascript:;">推广渠道</a>
                    <dl class="layui-nav-child">
                        <dd class="{if $Request.path == 'login/Show/index'}layui-this{/if}"><a href="/login/Show/index">进来流量</a></dd>
                        <dd class="{if $Request.path == 'login/Registered/index'}layui-this{/if}"><a href="/login/Registered/index">注册量</a></dd>
                    </dl>
                </li>

                <li class="layui-nav-item {if ($Request.path == 'login/Statistics/index') }layui-nav-itemed{/if}">
                    <a class="" href="javascript:;">统计</a>
                    <dl class="layui-nav-child">
                        <dd class="{if $Request.path == 'login/Show/Statistics'}layui-this{/if}"><a href="/login/Statistics/index">流量统计</a></dd>
                    </dl>
                </li>

            </ul>
        </div>
    </div>

    <div id="main" class="layui-body">
        <!-- 内容主体区域 -->
       <blockquote class="layui-elem-quote" style="margin: 15px"><!-- 内容变量--></blockquote>
        {block name="main"}{/block}
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 感谢
    </div>
</div>
<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use(['element','form'], function(){
        var form = layui.form;
        // 获取本地缓存中的token
        var tokenValue = layui.data('cache');
        if(tokenValue.token !== 'undefined'){
            $.ajax({
                url:"/api/v1.Token/verifyToken",
                headers:{"token":tokenValue.token},
                type:"post",
                dataType:"json",
                success:function(res){
                    // 200则token不失效
                    if(res.code == 200){
                        var token = layui.data('cache')
                        $.ajax({
                            url:"/login/Show/getUserData",
                            type:"post",
                            headers:{"token":token.token},
                            dataType:"json",
                            success:function (res) {
                                $('#title').html(res.name + '推广详情页面')
                                $('#username').html(res.name)
                                data = res.sign
                                for(var key in data){
                                    $("#signData").append("<option value='" + data[key] + "'>" + data[key] + "</option>");
                                }
                                form.render('select');
                            }
                        })
                    }
                    // 404则token失效
                    if(res.code == 404 || res.code == 401){
                        window.location.href = "/login/Index/Timeout"
                    }
                },
                error:function(error){
                    console.log(error.responseJSON.code)
                    if(error.responseJSON.code == 401){
                        window.location.href = "/login/Index/Timeout"
                    }
                }
            })
        }

    });

    // 清除token退出
    function showTime(){
        layui.use(['element','form'], function(){
            var tokenValue = layui.data('cache');
            if(tokenValue.token){
                layui.data('cache', {
                    key: 'token'
                    ,remove: true
                });
            }
            // location.reload();
            window.location.href="/login/Index/out"
        })

    }
    function updateStatua() {
        var url = window.location.href;
        layui.use(['layer'], function(){
            var token = layui.data('cache').token;
            var layer = layui.layer;
            $.ajax({
                url:"/login/Registered/updateAllStatus",
                type:"post",
                headers:{"token":token},
                dataType:"json",
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('更新成功,今天可用次数为'+ res.num + ',即将刷新页面');
                        setTimeout(function () {
                            window.location.href = url
                        }, 3000)
                    }
                    if(res.code == 400){
                        layer.msg('更新失败, 今天的可用次数为0');
                    }

                },
                error:function (error) {
                    layer.msg('更新成功');
                }
            })
        })
    }

    var tip_index = 0;
    $(document).on('mouseenter', '#updateAll', function(){
        tip_index = layer.tips('更新贷款状态，每天只能手动更新八次，后台每两个钟会自动更新一次，不会消耗手动更新次数', '#updateAll', {time: 0});
    }).on('mouseleave', '#updateAll', function(){
        layer.close(tip_index);
    });
</script>
</body>
</html>